﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@page import="com.zaofan.bean.AdminType"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
Admin admin = (Admin)session.getAttribute("admin");
if(admin == null){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
	}
if(admin.getType() != AdminType.admin.ordinal() &&  admin.getType() != 4){
	response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
	return;
}
	String shopId = request.getParameter("shopId");
	if(shopId == null){
		out.print("非法访问!!");
		return;
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品增加</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/bootstrap-timepicker.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/chosen.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
</script>
</head>
<body style="background-color: #fff;">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try {
				ace.settings.check('breadcrumbs', 'fixed')
			} catch (e) {
			}
		</script>
		<ul class="breadcrumb">
			<li><i class="icon-home home-icon"></i> <a
				href="<%=contextPath%>/admin/admin/index.jsp">首页</a></li>
			<li class="active">管理</li>
		</ul>
	</div>
	<div class="page-content">
		<div class="page-header">
			<h1>
				管理 <small> <i class="icon-double-angle-right"> 产品添加 </i>
				</small>
			</h1>
		</div>
		<!-- /.page-header -->
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<a href="javascript:history.go(-1);" class="btn btn-primary" role="button">返回</a>
				<div class="alert alert-info" role="alert">产品添加s</div>
				<div class="popover-inner" style="">
					<div class="popover-content" id="" style="">
						<form class="form-horizontal" style="padding-top: 10px;"
							method="post" id="shopForm">
							<input type="hidden" value="" name="shopId" ></input>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">产品名称：</label>
								<div class="col-sm-9">
									<input name="name" id="name" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group " >
								<label for="" class="col-sm-2 control-label">产品价格：</label>
								<div class="col-sm-9">
									<input name="price" id="price" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品描述：</label>
								<div class="col-sm-9 bootstrap-timepicker">
									<input id="des" name="des" type="text" class="form-control" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品类别：</label>
								<div class="col-sm-9">
									<select name="categoryId" id="categoryId">
									
									</select>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品图片：</label>
								<div class="col-sm-9">
									<input name="image" id="image" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<label for="" class="col-sm-2 control-label">产品详情页图片：</label>
								<div class="col-sm-9">
									<input name="bigImage" id="bigImage" class="form-control" value="" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
						</form>
					</div>
					<div class="popover-footer"
						style="overflow: hidden; text-align: center;">
						<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
							<i class="icon-ok"></i>取消
						</button>
						<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
							<i class="icon-edit"></i>保存
						</button>

					</div>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>

	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script
		src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-timepicker.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>

	<script type="text/javascript">
		init();
		
		function init(){
			$("#loading").show();
			$.ajax({
				url : contextPath + '/category',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'shop_category',
					shopId:shopId
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						var options = "<option value='-1'>请选择产品类别</option>";
						var data = rs.data;
						for(var i = 0 ; i < data.length ; i++){
							options += '<option value='+data[i].id+'>'+data[i].name+'</option>';
						}
						$("#categoryId").append(options);
						$("#categoryId").change(function(){
							
						});
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			});
			
		}
		
	
		$("#save").bind("click", function() {
			if ($("#shopName").val() == "") {
				showMessage("请输入店铺名称!!!");
				return;
			}
			if ($("#beginTime").val() == "") {
				showMessage("请输入开始营业时间!!!");
				return;
			}

			if ($("#endTime").val() == "") {
				showMessage("请输入结束时间!!!");
				return;
			}
			if ($("#shopDes").val() == "") {
				showMessage("请输入商铺的简单描述!!!");
				return;
			}
			if ($("#express").val()=="") {
				showMessage("请输入商铺的快递费!!!");
				return;
			}
			if (isNaN($("#express").val() )) {
				showMessage("商铺的快递费必须为数字!!!");
				return;
			}
			if ($("#minPrice").val() == "") {
				showMessage("请输入商铺起送价格!!!");
				return;
			}
			if (isNaN($("#minPrice").val())) {
				showMessage("商铺起送价格必须为数字!!!");
				return;
			}
			if($("input[name='lableId']:checked").length == 0){
				showMessage("请选择商铺类型!!!");
				return;
			}
			if($("input[name='expressLableId']:checked").length == 0){
				showMessage("请选择商铺配送类型!!!");
				return;
			}
			if($("input[name='expressLableId']:checked").length == 0){
				showMessage("请选择商铺配送类型!!!");
				return;
			}
			if($("input[name='payLableId']:checked").length == 0){
				showMessage("请至少选择一个商铺的支付方式!!!");
				return;
			}
			if ($("#cityId").val() == "") {
				showMessage("请选择商铺的城市信息!!!");
				return;
			}
			if ($("#areaId").val() == "") {
				showMessage("请选择商铺的区域信息!!!");
				return;
			}
			if($("input[name='builderIds']:checked").length == 0){
				showMessage("请至少选择一个商铺的支持的大楼!!!");
				return;
			}
			$("#loading").show();
			$("#shopForm").ajaxSubmit({
				type : "POST",
				url : contextPath + '/shop?action=add',
				dataType : 'json',
				success : function(data) {
					if (data.success) {
						showMessage(data.msg);
						setTimeout(function() {
							window.location.href = "shopList.jsp";
						}, 2000);
					} else {
						showMessage(data.msg);
					}
					$("#loading").hide();
				},
				error : function(msg) {
					$("#loading").hide();
					showMessage("操作失败");
				}
			});
		});
		$("#address").focus(function(){
			var val = $("#cityId").val();
			if(val == 0){
				showMessage("请选择商品城市信息");
				$(this).blur();
				return;
			}
		});
		$("#address").blur(function(){
			var val = $(this).val();
			if(val == ""){
				return ;
			}
			$.ajax({
				url : contextPath + '/position',
				type : "POST",
				dataType : 'json',
				data : {
					action : 'location',
					address:val,
					city:$("#cityName").val()
				},
				success : function(rs, textStatus, jqXHR) {
					$("#loading").hide();
					if (rs.success) {
						$("#jingInfo").show();
						$("#lon").val(rs.data.result.location.lng);
						$("#lat").val(rs.data.result.location.lat);
						$("#addressInfo").val("经度信息:"+ rs.data.result.location.lng + ",纬度信息:" + rs.data.result.location.lat);
					} else{
						showMessage(rs.msg);
					}
					$("#loading").hide();
				},
				error : function() {
					$("#loading").hide();
					showMessage("请稍后再试");
				}
			}); 
			
		});
		
		
	</script>
</body>
</html>